package com.glorysoft.wangnianxinpda.entity.net;

import androidx.fragment.app.FragmentManager;

import com.glorysoft.wangnianxinpda.base.App;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * @author lx
 * @date 2019/3/22
 * @desc
 */
public class ResponseEntity<T> implements Serializable {


    private ReturnEntity RETURN;

    private boolean Status;
    private String Msg;

    private T Data;

    private transient FreeUI_GeneralFragmentDialog tipDialog;

    public ResponseEntity() {
        this.RETURN = new ReturnEntity();
    }

    public ReturnEntity getRETURN() {
        return RETURN;
    }

    public void setRETURN(ReturnEntity RETURN) {
        this.RETURN = RETURN;
    }

    public boolean isStatus() {
        return Status;
    }

    public void setStatus(boolean status) {
        Status = status;
    }

    public String getMsg() {
        return Msg;
    }

    public void setMsg(String msg) {
        Msg = msg;
    }

    public T getData() {
        return Data;
    }

    public void setData(T data) {
        Data = data;
    }

    //获取到对象后，必须要判断是否获取成功
    public boolean isSuccess(boolean isHaveBody, FragmentManager fragmentManager) {
        if (Status) {
            if (isHaveBody) {
                if (Data == null) {
                    //FreeApi_ToastUtils.showFreeToast("暂无请求内容", context, false, Toast.LENGTH_SHORT);
                    showFailDialog("暂无请求内容", fragmentManager);
                    return false;
                } else {
                    if (Data instanceof ArrayList) {
                        if (((ArrayList) Data).size() > 0) {
                            return true;
                        } else {
                            //FreeApi_ToastUtils.showFreeToast("暂无请求数据", context, false, Toast.LENGTH_SHORT);
                            showFailDialog("暂无请求数据", fragmentManager);
                            return false;
                        }
                    } else {
                        return true;
                    }
                }
            } else {
                return true;
            }
        } else {
            showFailDialog(Msg , fragmentManager);
            //FreeApi_ToastUtils.showFreeToast(Response.getReturn().getReturnMessage(), context, false, Toast.LENGTH_SHORT);
            return false;
        }
    }
    private void showFailDialog(String message, FragmentManager fragmentManager) {
        tipDialog = FreeApi_DialogUtils.getConfirmDialog(App.app, "确定", message, new FreeUI_CommonCallback() {
            @Override
            public void onSuccess() {
            }
        });
        tipDialog.show(fragmentManager, "DIALOG");
    }
}
